package com.ce.controller;


import com.ce.entity.Customer;
import com.ce.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ce
 * @since 2022-01-02
 */
@RestController
@RequestMapping("/customer")
public class CustomerController {
    @Autowired
    CustomerService service;

    /**
     * 查询顾客信息
     */
    @PostMapping("/getCustomerList")
    public List<Customer> testSelect(Customer customer){
        List<Customer> customers = service.getList(customer);
        return customers;

    }
    /**
     * 删除顾客
     */
    @DeleteMapping("/deleteCustomer")
    public Integer deleteCustomer(Integer id){
        Integer res =service.deleteById(id);
        return res;
    }

    /**
     * 添加客户
     */
    @PostMapping("/addCustomer")
    public Map<String, String> insertCustomer(Customer customer){
        return service.addCustomer(customer);
    }


    /**
     * 修改顾客信息
     */
    @PostMapping("/updateCustomer")
    public Map<String, String> updateCustomer(HttpServletRequest request){
        Customer customer = new Customer();
        customer.setId(Integer.parseInt(request.getParameter("id")));
        customer.setCustomerNo(request.getParameter("customerNo"));
        customer.setCustomerName(request.getParameter("customerName"));
        customer.setCustomerSex(request.getParameter("customerSex"));
        customer.setCustomerAge(Integer.parseInt(request.getParameter("customerAge")));
        customer.setCustomerTel(request.getParameter("customerTel"));
        customer.setCustomerAddress(request.getParameter("customerAddress"));
        customer.setCustomerBankno(request.getParameter("customerBankno"));
        customer.setCustomerPostcode(request.getParameter("customerPostcode"));
        return service.updateCustomer(customer);
    }
}
